import random
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import style

interval0 = 0.5
interval1 = 0.5
credit = 0.5

intv0_list = [0.5]
intv1_list = [0.5]
credit_list = [0.5]
time_list = [0]

time = 1000

style.use('ggplot')

for i in range(time):
    # success_rate = random.random()
    # number = random.uniform(0, 100)
    # success_rate = number / 100
    success_rate = np.random.normal(0.5, 0.1)
    success_rate = max(0, success_rate)
    success_rate = min(1, success_rate)

    if success_rate < interval0 or success_rate > interval1:
        credit = (credit + success_rate) / 2
        interval0 = min(credit, success_rate)
        interval1 = max(credit, success_rate)
    
    # print(interval0, interval1, credit)

    time_list.append(i + 1)
    intv0_list.append(interval0)
    intv1_list.append(interval1)
    credit_list.append(credit)

plt.plot(time_list, credit_list)
plt.xlabel('times')
plt.ylabel('credit')
plt.show()

l1 = plt.plot(time_list, intv0_list, label='lower bound')
l2 = plt.plot(time_list, intv1_list, label='upper bound')
plt.legend(loc = 'upper right')
plt.show()